package com.car.loan.project.xr.controller.after;

import com.car.loan.framework.aspectj.lang.annotation.Log;
import com.car.loan.framework.aspectj.lang.enums.BusinessType;
import com.car.loan.framework.web.domain.AjaxResult;
import com.car.loan.project.xr.service.AdvancesService;
import com.car.loan.project.xr.service.UrgentService;
import com.car.loan.project.xr.util.bo.business.after.OverdueAdvancesBo;
import com.car.loan.project.xr.util.bo.business.after.OverdueUrgentLogBo;
import com.car.loan.project.xr.util.bo.business.after.OverdueUrgentLogPageParam;
import com.car.loan.project.xr.util.vo.after.OverdueAdvancesInfo;
import com.car.loan.project.xr.util.vo.after.OverdueUrgentLogInfo;
import com.car.loan.project.xr.util.vo.after.OverdueUrgentLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangding
 * @date 2020/2/26 22:13
 */
@RestController
@RequestMapping("xr/advances")
@Api(value = "逾期垫款", tags = "贷后管理-逾期垫款")
public class AdvancesController {

    @Autowired
    private AdvancesService advancesService;

    @Autowired
    private UrgentService urgentService;

    @PreAuthorize("@ss.hasPermi('overdue:advances:list')")
    @GetMapping("list")
    @ApiOperation(value = "垫款列表", responseContainer = "list", response = OverdueUrgentLogVo.class)
    public AjaxResult list(@Valid OverdueUrgentLogPageParam overdueUrgentLogPageParam) {
        return AjaxResult.success(urgentService.getOverdueUrgentLogPage(overdueUrgentLogPageParam));
    }

    @PreAuthorize("@ss.hasPermi('overdue:advances:query')")
    @GetMapping("{loanId}")
    @ApiOperation(value = "垫款详情", response = OverdueAdvancesInfo.class)
    public AjaxResult info(@PathVariable Long loanId) {
        return AjaxResult.success(advancesService.info(loanId));
    }

    @PreAuthorize("@ss.hasPermi('overdue:advances:input')")
    @PostMapping("input")
    @ApiOperation(value = "垫款录入")
    @Log(title = "逾期催收录入", businessType = BusinessType.INSERT)
    public synchronized AjaxResult input(@RequestBody @Valid OverdueAdvancesBo overdueAdvancesBo) {
        return advancesService.input(overdueAdvancesBo);
    }
}
